package com.hjs.test.util;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;

public class IntrCaller {

    private static final String partnerId = "bdckdj";
    private static final String secret = "bdckdj123";

    /**
     * 分页获取用户变更记录
     */
    public static void getUsers(){
        String url = "http://newapi.zhihuishitang.net/gateway/openApi/user/V2/sync/get";
        JSONObject param = new JSONObject();
        param.put("partnerId",partnerId);
        param.put("accessToken",RedissonRedisTokenUtils.getToken());
        JSONObject bizData = new JSONObject();
        bizData.put("pageSize","10");
        bizData.put("lastId","0");
        param.put("bizData",bizData);
        String response = HttpRequest.post(url).setConnectionTimeout(15000).setReadTimeout(30000)
                .body(param.toJSONString())
                .header("sign",SignUtils.encrypt(param.toJSONString()+secret))
                .execute().body();
        System.out.println(response);
    }

    /**
     * 获取余额
     */
    public static void getBalance(){
        String url = String.format("http://newapi.zhihuishitang.net/gateway/openApi/user/V2/getRemainingBalance?cardNo=%s","3212888");
        JSONObject param = new JSONObject();
        param.put("partnerId",partnerId);
        param.put("accessToken",RedissonRedisTokenUtils.getToken());

        String response = HttpRequest.post(url).setConnectionTimeout(15000).setReadTimeout(30000)
                .body(param.toJSONString())
                .header("sign",SignUtils.encrypt(param.toJSONString()+secret))
                .execute().body();
        System.out.println(response);
    }

    /**
     * 扣款
     */
    public static void pay(){
        String url = "http://newapi.zhihuishitang.net/gateway/openApi/order/V2/pay/userPricePay";
        JSONObject param = new JSONObject();
        param.put("partnerId",partnerId);
        param.put("accessToken",RedissonRedisTokenUtils.getToken());
        JSONObject bizData = new JSONObject();
        bizData.put("userId","3212888");
        bizData.put("cashierId","1");
        bizData.put("outTradeNo","12333445566");
        bizData.put("source","0");
        bizData.put("cardNo","1");
        bizData.put("price","1.23");
        bizData.put("payType","1");

        param.put("bizData",bizData);
        String response = HttpRequest.post(url).setConnectionTimeout(15000).setReadTimeout(30000)
                .body(param.toJSONString())
                .header("sign",SignUtils.encrypt(param.toJSONString()+secret))
                .execute().body();
        System.out.println(response);
    }

    /**
     * 退款
     */
    public static void refund(){
        String url = "http://newapi.zhihuishitang.net/gateway/openApi/order/V2/pay/refundOrder";
        JSONObject param = new JSONObject();
        param.put("partnerId",partnerId);
        param.put("accessToken",RedissonRedisTokenUtils.getToken());
        JSONObject bizData = new JSONObject();
        bizData.put("orderNo","111111111111111");
        param.put("bizData",bizData);
        String response = HttpRequest.post(url).setConnectionTimeout(15000).setReadTimeout(30000)
                .body(param.toJSONString())
                .header("sign",SignUtils.encrypt(param.toJSONString()+secret))
                .execute().body();
        System.out.println(response);
    }
    public static void main(String[] args) {
        getUsers();
    }
}
